package source.events.action;

import source.model.*;
import source.model.type.*;
import source.view.MainScreen;

public class DropItemAction implements Action{

	public DropItemAction(){
	}
	
	public ActionResult execute(DataHandler dh){
		GameObject executor=(Unit)dh.getCurrentSelection();
		if(!executor.objectType().equals(GameObjectType.UNIT))
			return ActionResult.IMPOSSIBLE;
		Unit u=(Unit)executor;
		if(u.getMissionFlag())
		{
			MainScreen.writeToConsole("Current selection is on a mission");
			return ActionResult.IMPOSSIBLE;
		}
		Position p=dh.getCurrentPosition();
		Item item = u.getItem();
		if(item==null)
			return ActionResult.IMPOSSIBLE;
		dh.reassign(item, p);
		dh.returnObject(executor);
		MainScreen.writeToConsole("You have dropped " + item);
		return ActionResult.SUCCESS;
	}
}
